//
// Created by gxy on 2025/8/31.
//

#include <common.h>

int mainElement(vector<int> nums) {
    unordered_map<int,int> mp;
    int max_ele=-1,max_cnt=0;
    for (auto& i:nums) {
        int cnt=++mp[i];
        if (cnt>max_cnt) {
            max_cnt=cnt;
            max_ele=i;
        }
    }
    if (max_cnt>nums.size()/2) {
        return max_ele;
    }
    return -1;
}
int main() {
    vector<int> nums{0,5,5,3,5,7,5,5};
    vector<int> nums1={0,5,5,3,5,1,5,7};
    int res= mainElement(nums);
    cout<<res<<endl;

    unordered_map<int,int> mp;

    return 0;
}
